package com.zcah.mask.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zcah.common.util.PageUtils;
import com.zcah.common.vo.Query;
import com.zcah.common.vo.R;
import com.zcah.mask.domain.MaskMethodDO;
import com.zcah.mask.service.MaskMethodService;

/**
 * 脱敏方法
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-07-06 16:26:24
 */
 
@RestController
@RequestMapping("/v1/maskMethod")
public class MaskMethodController {

	private final MaskMethodService maskMethodService;

	@Autowired
	public MaskMethodController(MaskMethodService maskMethodService) {
		this.maskMethodService = maskMethodService;
	}

	@GetMapping("/list")
	//@RequiresPermissions("mask:maskMethod:maskMethod")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<MaskMethodDO> maskMethodList = maskMethodService.list(query);
		int total = maskMethodService.count(query);
		PageUtils pageUtils = new PageUtils(maskMethodList, total);
		return pageUtils;
	}
	
	/**
	 * 保存
	 */
	@PostMapping("/save")
	@RequiresPermissions("mask:maskMethod:add")
	public R save( MaskMethodDO maskMethod){
		if(maskMethodService.save(maskMethod)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("mask:maskMethod:edit")
	public R update( MaskMethodDO maskMethod){
		maskMethodService.update(maskMethod);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@RequiresPermissions("mask:maskMethod:remove")
	public R remove( Integer maskMethodId){
		if(maskMethodService.remove(maskMethodId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@RequiresPermissions("mask:maskMethod:remove")
	public R remove(@RequestParam("ids[]") Integer[] maskMethodIds){
		maskMethodService.batchRemove(maskMethodIds);
		return R.ok();
	}
	
}
